package 单周赛.history;

/**
 *
 */
public class 第306场单周赛 {

    public static void main(String[] args) {

        int[][] grid = {{9, 9, 8, 1}, {5, 6, 2, 6}, {8, 2, 6, 4}, {6, 2, 2, 2}};
        largestLocal(grid);

        int[] edges = {2, 0, 0, 2};
        System.out.println(edgeScore(edges));

    }

    public static int[][] largestLocal(int[][] grid) {
        int n = grid.length;
        int[][] ans = new int[n - 2][n - 2];

        for (int row = 1; row < n - 1; row++) {
            for (int column = 1; column < n - 1; column++) {
                ans[row - 1][column - 1] = Math.max(grid[row][column], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row - 1][column], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row + 1][column], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row][column - 1], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row][column + 1], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row + 1][column - 1], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row + 1][column + 1], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row - 1][column + 1], ans[row - 1][column - 1]);
                ans[row - 1][column - 1] = Math.max(grid[row - 1][column - 1], ans[row - 1][column - 1]);
            }
        }
        return ans;
    }

    public static int edgeScore(int[] edges) {
        long maxScore = 0;
        int ans = -1;
        // 得分可能 int 溢出，使用数组记录更快
        long[] scoreArr = new long[edges.length];
        for (int i = 0; i < edges.length; i++) {
            int next = edges[i];
            scoreArr[next] += i;
            Long score = scoreArr[next];
            if (score > maxScore) {
                maxScore = score;
                ans = next;
            } else if (score == maxScore) {
                ans = Math.min(ans, next);
            }
        }
        return ans;
    }

}
